﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Threading;
using WBasicClassLib.Helper;
using WBasicClassLib.Logger;

namespace DBHelper_Sample
{
    //注：请自己设置数据源，这里给出的链接字符串只适应于编写者的机器

    public partial class Form1 : Form
    {
        DBHelper DbReader;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DbReader = null;
            SqlConnection Conn = new SqlConnection("Server=(local);Database=Northwind;uid=sa;pwd=sa;");
            DbReader = new DBHelper(Conn);
            DataTable dt = DbReader.GetDataSet("select * from Products").Tables[0];
            dataGridView1.DataSource = dt;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DbReader = null;
            OleDbConnection Conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AccessTestDB.mdb");
            DbReader = new DBHelper(Conn);
            DataTable dt = DbReader.GetDataSet("select * from [Users]").Tables[0];
            dataGridView1.DataSource = dt;
        }

        private void Test()
        {
                OleDbConnection Conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AccessTestDB.mdb");
                DbReader = new DBHelper(Conn);
                DbReader.ExecuteCommand("insert into Users([Name], [Sex], [Age]) values('New', 'M', 100)");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; ++i)
            {
                Thread t = new Thread(new ThreadStart(Test));
                t.Start();
            }
        }
    }
}
